package com.lshl.lingshang.model;


import androidx.lifecycle.MutableLiveData;

import com.lshl.lingshang.bean.ErrorBean;
import com.lshl.lingshang.http.lifecycle.BaseViewModel;
import com.lshl.lingshang.http.manager.SubscriberManger;
import com.lshl.lingshang.ui.bean.BannerBean;
import com.lshl.lingshang.ui.request.CommonRequestBean;

import java.io.IOException;

/**
 * Description：
 * Created on 2020/6/8
 * Author : 郭
 */
public class MainModel extends BaseViewModel {
    /**
     * 当数据请求成功回调
     */
    public MutableLiveData<BannerBean> news;

    @Override
    public void setTitle() {
        title.setTitleBar(true, "测试databindingtitle");
    }

    public void requestImg() {
        showDialog.setValue(true);
        CommonRequestBean body = new CommonRequestBean();
        manager.requsetStartUpScreen(body).compose(compose()).subscribe(new SubscriberManger<BannerBean>() {
            @Override
            public void onSuccess(BannerBean result, String msg) throws IOException {
                showDialog.setValue(false);
                if (result != null) {
                    news.postValue(result);
                }
            }

            @Override
            public void onFailure(int code, String msg) throws IOException {
                showDialog.setValue(false);
                errorMsg.postValue(new ErrorBean(code,msg));
            }
        });
    }

    public MutableLiveData<BannerBean> getNewsList() {
        if (news == null) {
            news = new MutableLiveData<>();
        }
        return news;
    }



}
